<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
  xmlns:podcast="https://podcastindex.org/namespace/1.0"
>
  <channel>
    <title><%= @feed.name %></title>
    <copyright>All rights reserved</copyright>
    <language>en-us</language>
    <description><%= @feed.description %></description>
    <itunes:author>Changelog Media</itunes:author>
    <itunes:block>yes</itunes:block>
    <itunes:explicit>no</itunes:explicit>
    <itunes:summary><%= @feed.description %></itunes:summary>
    <itunes:image href="<%= PodcastView.cover_url(@feed) %>"/>
    <itunes:owner>
      <itunes:name>Changelog Media</itunes:name>
      <itunes:email>editors@changelog.com</itunes:email>
    </itunes:owner>
  <%= for episode <- @episodes do %>
    <item>
      <title><%= custom_episode_title(@feed, episode) |> escaped() %></title>
      <link><%= url(~p"/#{episode.podcast.slug}/#{episode.slug}") %></link>
      <guid isPermaLink="false"><%= EpisodeView.guid(episode) %></guid>
      <pubDate><%= TimeView.rss(episode.published_at) %></pubDate>
    <%= if @feed.plusplus do %>
      <enclosure url="<%= EpisodeView.plusplus_url(episode) %>" length="<%= episode.plusplus_bytes %>" type="audio/mpeg" />
    <% else %>
      <enclosure url="<%= EpisodeView.audio_url(episode) %>" length="<%= episode.audio_bytes %>" type="audio/mpeg" />
    <% end %>
      <description><%= SharedHelpers.md_to_text(episode.summary) %></description>
      <content:encoded><%= render("_show_notes.xml", episode: episode, plusplus: @feed.plusplus) %></content:encoded>
      <itunes:episodeType><%= episode.type %></itunes:episodeType>
      <itunes:image href="<%= EpisodeView.cover_url(episode) %>"/>
    <%= if @feed.plusplus do %>
      <itunes:duration><%= TimeView.duration(episode.plusplus_duration) %></itunes:duration>
    <% else %>
      <itunes:duration><%= TimeView.duration(episode.audio_duration) %></itunes:duration>
    <% end %>
      <itunes:explicit>no</itunes:explicit>
      <itunes:subtitle><%= escaped(episode.subtitle) %></itunes:subtitle>
      <itunes:summary><%= SharedHelpers.md_to_text(episode.summary) %></itunes:summary>
      <dc:creator>Changelog Media</dc:creator>
      <itunes:author>Changelog Media</itunes:author>
      <%= render_many(episode.hosts, __MODULE__, "_person.xml", as: :person, role: "host") %>
      <%= render_many(episode.guests, __MODULE__, "_person.xml", as: :person, role: "guest") %>
    <%= if Episode.has_transcript(episode) do %>
      <podcast:transcript url="<%= url(~p"/#{episode.podcast.slug}/#{episode.slug}/transcript") %>" type="text/html" />
    <% end %>
    <%= if Enum.any?(episode.audio_chapters) do %>
      <%= if @feed.plusplus do %>
        <podcast:chapters url="<%= url(~p"/#{episode.podcast.slug}/#{episode.slug}/chapters?pp=true") %>" type="application/json+chapters" />
      <% else %>
        <podcast:chapters url="<%= url(~p"/#{episode.podcast.slug}/#{episode.slug}/chapters") %>" type="application/json+chapters" />
      <% end %>
    <% end %>
    <%= if episode.socialize_url do %>
      <podcast:socialInteract uri="<%= episode.socialize_url %>" protocol="activitypub" />
    <% end %>
    </item>
  <% end %>
  </channel>
</rss>
